package cn.kgm.makeGodV2.ruleEngine;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @Version 1.8
 * @Author: Kappi
 * @Date: 2025-9-24 10:27
 * @Description: cn.kgm.makeGodV2.ruleEngine.CultivationGame
 */
public class CultivationGame {
    public static void main(String[] args) {
        // 初始化规则引擎并注册规则
        RuleEngine ruleEngine = RuleEngine.getInstance();
        ruleEngine.registerRule(new RealmCheckRule());
        ruleEngine.registerRule(new ItemCheckRule());
        ruleEngine.registerRule(new RandomTriggerRule());

        // 创建玩家数据
        Map<String, Integer> playerItems = new HashMap<>();
        playerItems.put("避毒丹", 3);
        playerItems.put("飞行符", 1);
        playerItems.put("灵石", 100);

        Map<String, Integer> requiredItems = new HashMap<>();
        requiredItems.put("避毒丹", 2);
        requiredItems.put("飞行符", 1);

        // 设置规则上下文
        // 这里其实是用户完整信息
        RuleContext context = new RuleContext();
        context.setParam("playerRealm", "金丹期");
        context.setParam("requiredRealm", "筑基期");
        context.setParam("triggerRate", 0.3);
        context.setParam("playerItems", playerItems);
        context.setParam("requiredItems", requiredItems);

        // 执行单个规则
        System.out.println("=== 执行单个规则 ===");
        RuleResult<Boolean> realmResult = ruleEngine.executeRule("REALM_CHECK", context);
        System.out.println(realmResult.getMessage() + ", 数据: " + realmResult.getData());

        // 执行批量规则
        System.out.println("\n=== 执行批量规则 ===");
        List<RuleResult<?>> results = ruleEngine.executeRules(context);
        for (RuleResult<?> result : results) {
            System.out.println(result.getMessage() + " - 成功: " + result.isSuccess());
        }

        // 测试物品不足的情况
        System.out.println("\n=== 测试物品不足 ===");
        Map<String, Integer> insufficientItems = new HashMap<>();
        insufficientItems.put("避毒丹", 1); // 只有1个，需要2个
        insufficientItems.put("飞行符", 1);

        RuleContext insufficientContext = new RuleContext();
        insufficientContext.setParam("requiredItems", requiredItems);
        insufficientContext.setParam("playerItems", insufficientItems);

        RuleResult<Map<String, Integer>> itemResult = ruleEngine.executeRule("ITEM_CHECK", insufficientContext);
        System.out.println(itemResult.getMessage());
        System.out.println("缺少物品: " + itemResult.getData());
    }
}
